package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HmzEra;
import com.ruoyi.system.service.IHmzEraService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年代Controller
 * 
 * @author ruoyi
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/system/era")
public class HmzEraController extends BaseController
{
    @Autowired
    private IHmzEraService hmzEraService;

    /**
     * 查询年代列表
     */
    @PreAuthorize("@ss.hasPermi('system:era:list')")
    @GetMapping("/list")
    public TableDataInfo list(HmzEra hmzEra)
    {
        startPage();
        List<HmzEra> list = hmzEraService.selectHmzEraList(hmzEra);
        return getDataTable(list);
    }

    /**
     * 导出年代列表
     */
    @PreAuthorize("@ss.hasPermi('system:era:export')")
    @Log(title = "年代", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HmzEra hmzEra)
    {
        List<HmzEra> list = hmzEraService.selectHmzEraList(hmzEra);
        ExcelUtil<HmzEra> util = new ExcelUtil<HmzEra>(HmzEra.class);
        util.exportExcel(response, list, "年代数据");
    }

    /**
     * 获取年代详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:era:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hmzEraService.selectHmzEraById(id));
    }

    /**
     * 新增年代
     */
    @PreAuthorize("@ss.hasPermi('system:era:add')")
    @Log(title = "年代", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HmzEra hmzEra)
    {
        return toAjax(hmzEraService.insertHmzEra(hmzEra));
    }

    /**
     * 修改年代
     */
    @PreAuthorize("@ss.hasPermi('system:era:edit')")
    @Log(title = "年代", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HmzEra hmzEra)
    {
        return toAjax(hmzEraService.updateHmzEra(hmzEra));
    }

    /**
     * 删除年代
     */
    @PreAuthorize("@ss.hasPermi('system:era:remove')")
    @Log(title = "年代", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hmzEraService.deleteHmzEraByIds(ids));
    }
}
